package com.example.shadingjdbc.demos.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.example.shadingjdbc.entity.SysUser;
import com.example.shadingjdbc.service.UserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
@RequestMapping("/v1/api")
public class SysUserController {

    @Autowired
    private UserService userService;



    @PostMapping("/user")
    public String addUser(@RequestBody SysUser sysUser) {
         userService.insertUser(sysUser);
        return "插入数据成功";
    }
    @GetMapping("/user/name/{username}")
    public SysUser getUser(@PathVariable("username") String username){
        return userService.getDataByUsername(username);
    }
    @GetMapping("/user/age/{age}")
    public SysUser getUser(@PathVariable("age") Integer age){
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.gt("age",age).last("limit 1");
        return userService.getOne(queryWrapper);
    }
    @DeleteMapping("/user/id/{id}")
    public Boolean removeUser(@PathVariable("id") String id){
        SqlRunner.db().selectCount("call demo_sp()");
        return true;
    }
}
